<template>
  <div class="view-container notice-list">
    <header class="view-header">
      <div class="header-container">
        <div class="header-title">
          <i class="el-icon-s-grid"></i>
          <span>收文处理</span>
        </div>
        <div class="header-form">
          <div class="header-form-item">
            <el-button icon="el-icon-refresh-right" @click="refresh">刷新</el-button>
          </div>
          <div class="header-form-item">
            <el-button type="success" icon="el-icon-edit" @click="edit">编辑</el-button>
          </div>
          <!--收文处理暂时没有删除功能-->
<!--          <div class="header-form-item">
            <el-button type="danger" :loading="delLoading" icon="el-icon-delete" @click="del">删除</el-button>
          </div>-->
          <!--更多-->
          <!--<div class="header-form-item">
            <el-dropdown @command="handleCommand">
              <el-button type="default" :loading="delLoading">
                更多<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>
              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item icon="el-icon-refresh-right" class="color-refresh-item" command="refresh">刷新</el-dropdown-item>
                <el-dropdown-item icon="el-icon-edit" class="color-edit-item" command="edit">编辑</el-dropdown-item>
                <el-dropdown-item icon="el-icon-delete" class="color-del-item" command="del">{{isBatchesDel}}</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>-->
<!--          <div class="header-form-item">
            <el-button type="success" icon="el-icon-s-check" @click="openCheckDialog">提交审核</el-button>
          </div>-->
          <!--搜索-->
          <!--          <div class="header-form-item">
                      <el-button type="primary" icon="el-icon-search" @click="fetchData">查询</el-button>
                    </div>
                    &lt;!&ndash;按标题查询&ndash;&gt;
                    <div class="header-form-item title-search">
                      <el-input v-model="receipt.docTitle" placeholder="标题"></el-input>
                    </div>-->

        </div>
      </div>
    </header>

    <section class="table-container view-section">
      <el-table
        ref="table"
        :data="tableData"
        stripe
        border
        @selection-change="handleSelectionChange"
        @row-click="handleRowClick"
      >
        <el-table-column type="selection"/>
        <el-table-column label="文档标题" align="left">
          <template slot-scope="s">
            <el-link @click="toDetail(s.row.docId)" v-text="s.row.docTitle"></el-link>
          </template>
        </el-table-column>
        <el-table-column prop="receiptDate" label="来文日期" align="center" width="150" sortable/>
        <el-table-column prop="codeName" label="来文文号" align="center" width="150"/>
        <el-table-column prop="codeNo" label="收文号" align="center" width="150"/>
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="s">
            <el-link @click="openCheckDialog(s.row.docId)"><i class="el-icon-s-check">审核</i></el-link>
          </template>
        </el-table-column>
      </el-table>
    </section>
    <footer>
      <el-pagination

        :page-sizes="[10, 20, 50, 100]"
        style="text-align: right"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
        :page-size="page.size"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </footer>

    <el-dialog
      title="选择审核人"
      :visible.sync="checkDialog"
      :before-close="beforeClose"
      :close-on-click-modal="false"
    >
      <div class="checkerList">
        <el-form>
          <el-select v-model="checkerId">
            <el-option
              v-for="item in userList"
              :key="item.value"
              :label="item.label"
              :value="item.value"></el-option>
          </el-select>
        </el-form>
      </div>
      <div slot="footer">
        <el-button
          type="success"
          @click="submitChecker"
          :loading="submitCheckerLoading">确 定
        </el-button>
        <el-button type="default" @click="closeDialog">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import userAPI from '@/api/system/user'
  import receiptAPI from '@/api/receipt/receipt'
  import listMixin from '@/mixin/listMixin'

  export default {
    name: 'ReceiptHandleList',
    mixins: [listMixin],
    data() {
      return {
        receipt: {
          docId: null,
          docTitle: '',
          docCode: '',
          codeName: '',
          codeYear: '',
          codeNo: '',
          receiptDate: '',
          receiptUnit: '',
          archiveType: '',
          docLevel: '',
          storePeriod: '',
          receiptContent: '',
          auditor: '',
          docState: '',
          signIndex: '',
          signCount: '',
          parentDocId: '',
          hasIssue: '',
          creator: ''
        },
        dateArr: [],
        departmentList: [],
        pickerOptions: {
          shortcuts: [{
            text: '一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(start.getTime() + 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          }, {
            text: '一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(start.getTime() + 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          }, {
            text: '三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              end.setTime(start.getTime() + 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }]
        },
        checkDialog: false,
        showHideMenu: false,
        userList: [],
        submitCheckerLoading: false,
        checkerId: '',
        mixinParams: {
          addUrl: '',
          editUrl: '',
          propertyName: 'docId',
          API: receiptAPI
        },
        curSelected:''
      }
    },
    created() {
      this.getUserList()
    },
    computed: {},
    methods: {
      toDetail(id){
        // let-todo 收文处理查看详细
        /*this.$router.push('/')*/
      },
      submitChecker() {
        if (this.checkerId === '') {
          this.$message.warning('请选择审核人')
          return false
        }
        if (this.submitCheckerLoading) {
          return false
        }
        this.submitCheckerLoading = true
        receiptAPI.audit({ auditor: this.checkerId, id: this.curSelected }).then(res => {
          this.submitCheckerLoading = false
          this.$message.success('提交审核成功')
          this.checkDialog = false
          this.fetchData()
        }).catch(err => {
          this.submitCheckerLoading = false
          console.log(err)
        })
      },
      closeDialog() {
        this.checkerId = ''
        this.checkDialog = false
      },
      beforeClose(done) {
        this.checkerId = ''
        this.checkDialog = false
        done(true)
      },
      openCheckDialog(id) {
/*        if (this.multipleSelected.length === 0) {
          this.$message.warning('请选择要提交审核的行')
          return
        }*/
        this.curSelected = id
        this.checkDialog = true
      },
      getUserList() {
        userAPI.getSelectList('').then(res => {
          this.userList = res.result
        }).catch(err => {
          console.log(err)
        })
      },
      fetchData() {
        receiptAPI.getList(this.page.index, this.page.size).then(res => {
          console.log(res.records)
          this.page.total = res.total
          this.tableData = res.records
        }).catch(err => {
          console.log(err)
        })
      },
      searchForm() {
        this.showHideMenu = false
        if (this.dateArr.length !== 0) {
          this.notice.startTime = this._util.formatDateToString(this.dateArr[0])
          this.notice.endTime = this._util.formatDateToString(this.dateArr[1])
        }
        this.fetchData()
      },
      resetForm(form) {
        this.$refs[form].resetFields()
        this.dateArr.splice(0, 2)
        this.fetchData()
      },
      // let-todo 收文处理缺少编辑页面路由，和添加页面的路由。
      edit() {
        if (this.multipleSelected.length === 0) {
          this.$message.warning('请选择要编辑的行')
        } else {
          this.$router.push('/portal/edit-notice/' + this.multipleSelected[0])
        }
      },
      toAddPage() {
        this.$router.push('/portal/add-notice')
      }
    }
  }
</script>

<style lang="scss">
  .notice-list {
    .el-dialog {
      width: 400px;
    }

    .el-select {
      width: 100%;
    }

    .el-dialog__footer {
      padding-bottom: 10px;
    }
  }

</style>

<style scoped lang="scss">

  .tool {
    font-size: 13px;
    color: #ccc;
  }

  .checkerList {
    li {
      line-height: 30px;
    }
  }


</style>

